package src;
public class ThreadDemo extends Thread{
    private Thread th4test;
    private String threadName;

    public ThreadDemo(String threadName){
        this.threadName = threadName;
    }

    public void run(){
        System.out.println("Running " + threadName);
        try{
            for(int i=4;i>0;i--){
                System.out.println("Thread:"+threadName+" - "+i);
                Thread.sleep(1000);
            }
        }catch(InterruptedException e){
            System.out.println("Thread " + threadName+" was interrupted");
        }
        System.out.println("Thread: " + threadName+ "is Exiting");
    }
    public void start () {
        System.out.println("Starting " +  threadName );
        if (th4test == null) {
           th4test = new Thread (this, threadName);
           th4test.start ();
        }
     }
}

